import {
	MPickupView2ActionType,
	IMPickupView2Ability,
	IMPickupView2ControllerParams,
	IMPickupView2Model,
	IMPickupView2Store,
	IParam,
	IViewEvent,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getViewClassNames,
	useViewAction,
	useViewBasic,
	useViewControllerParams,
	handlePickupViewButtonAction,
	handleMPickupViewPickButtonAction,
	handleMPickupViewAction,
	setExpViewSplit,
	useViewProps,
} from '../use-view';

/**
 * 获取数据多项选择视图2输入参数
 *
 * @export
 * @return {*}
 */
export function useMPickupView2Props() {
	return {
		...useViewProps(),
	};
}

/**
 * 获取数据多项选择视图2基础
 *
 * @export
 * @param {IMPickupView2Model} model 数据多项选择视图2模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useMPickupView2Basic(model: IMPickupView2Model, props: IParam) {
	const getClassNames = (props: IParam) => {
		return getViewClassNames(model, props);
	};
	return {
		...useViewBasic(model, props),
		getClassNames,
		handlePickupViewButtonAction,
		handleMPickupViewPickButtonAction,
		handleMPickupViewAction,
	};
}

/**
 * 数据多项选择视图2行为
 *
 * @export
 */
export function useMPickupView2Action(controller: any) {
	const getPanelItemClass = (item: IParam) => {
		return {
			'picker-item': true,
			'is-active':
				controller.store.panelSelectedKeys.indexOf(item.srfkey) !== -1,
		};
	};
	const handleSplitChange = (model: any, split: number) => {
		setExpViewSplit(model, split);
	};
	return {
		...useViewAction(controller),
		getPanelItemClass,
		handleSplitChange,
	};
}

/**
 * 获取数据多项选择视图2控制器输入参数
 *
 * @export
 * @param {IMPickupView2Model} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<MPickupView2ActionType, IMPickupView2Ability>>} evt
 * @return {*}  {IMPickupView2ControllerParams<MPickupView2ActionType, IMPickupView2Ability>}
 */
export function useMPickupView2ControllerParams(
	model: IMPickupView2Model,
	props: IParam,
	evt: QXEvent<IViewEvent<MPickupView2ActionType, IMPickupView2Ability>>
): IMPickupView2ControllerParams<MPickupView2ActionType, IMPickupView2Ability> {
	return {
		...useViewControllerParams<IMPickupView2Store, IMPickupView2Model>(
			model,
			props,
			evt
		),
	};
}
